//
//  YuYueNavTitleView.m
//  FD
//
//  Created by xiaofang wang on 2018/11/9.
//  Copyright © 2018年 ZhiYuan Network. All rights reserved.
//

#import "YuYueNavTitleView.h"

@interface YuYueNavTitleView()
/**1.地址按钮*/
@property (nonatomic,  strong) UILabel *addressLb;
/**2.送达时间lb 富文本*/
@property (nonatomic,  strong) UILabel *songDaTimeLb;

@end

@implementation YuYueNavTitleView

- (instancetype)initWithFrame:(CGRect)frame title:(NSString *)title timestr:(NSString *)timeStr {
    
    self = [super initWithFrame:frame];
    if (self) {
        [self setupViewTitle:title time:timeStr];
    }
    return self;
}

- (void)setupViewTitle:(NSString *)title time:(NSString *)timeStr {
    //设置frame
    CGFloat s_w = self.bounds.size.width;
    CGFloat s_h = self.bounds.size.height;
    
    self.addressLb.frame = CGRectMake(0, 0, s_w, s_h*0.5);
    self.songDaTimeLb.frame = CGRectMake(0, self.addressLb.rb_bottom, s_w, s_h * 0.5);
    [self addSubview:self.addressLb];
    [self addSubview:self.songDaTimeLb];
    
    _addressLb.text = title;
    
    //富文本同时国际化
    _songDaTimeLb.attributedText = [self xxxxtimeStampStr:timeStr];
}

- (NSMutableAttributedString *)xxxxtimeStampStr:(NSString *)timestampStr{
    //预约点餐
    NSString *leftStr = @"预约点餐 ";
    
    //中间文字黑色的，两边文字是红色的
    NSString *centerStr = @"|用餐时间:";
    
    //用餐时间
    NSString *rightStr = timestampStr; //外面转好了传过来直接用
    NSString *resultStr = [NSString stringWithFormat:@"%@%@%@",leftStr,centerStr,rightStr];
    NSRange centerRange = [resultStr rangeOfString:centerStr]; //中间的字符串黑色的
    
    //富文本
    UIColor *blackColor = [UIColor blackColor];
    UIColor *redColor = [UIColor redColor];
    UIColor *clearColor = [UIColor clearColor];
    
    //属性
    NSDictionary *attDic = @{NSForegroundColorAttributeName:redColor,NSFontAttributeName:[UIFont systemFontOfSize:16.0*kScaleFit]};
    //富文本
    NSMutableAttributedString *attM = [[NSMutableAttributedString alloc] initWithString:resultStr attributes:attDic];
    [attM yy_setTextHighlightRange:centerRange color:blackColor backgroundColor:clearColor tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
    }];
    
    //返回
    return attM;
}


///getter
- (UILabel *)addressLb {
    if (!_addressLb) {
        _addressLb = [UILabel new];
        _addressLb.textAlignment = NSTextAlignmentCenter;
    }
    return _addressLb;
}

- (UILabel *)songDaTimeLb {
    if (!_songDaTimeLb) {
        _songDaTimeLb = [[UILabel alloc] init];
        _songDaTimeLb.text = @"外送|约40分钟送达";
        _songDaTimeLb.textAlignment = NSTextAlignmentCenter;
    }
    return _songDaTimeLb;
}

@end
